package com.handinfo.android.ui.window;

import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import android.R.string;
import android.graphics.Bitmap;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.core.graphics.DWFont;
import com.handinfo.android.core.net.GameProtocol;
import com.handinfo.android.core.resource.Resource;
import com.handinfo.android.game.GameActor;
import com.handinfo.android.game.GameMessage;
import com.handinfo.android.game.Role;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWControlTools;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWAnimationBox;
import com.handinfo.android.uicontrols.controls.DWBackground;
import com.handinfo.android.uicontrols.controls.DWCheckbox;
import com.handinfo.android.uicontrols.controls.DWDialogMenu;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWLabel;
import com.handinfo.android.uicontrols.controls.DWListSubItem;
import com.handinfo.android.uicontrols.controls.DWListbox;
import com.handinfo.android.uicontrols.controls.DWMessageBox;
import com.handinfo.android.uicontrols.controls.DWPopMenu;
import com.handinfo.android.uicontrols.controls.DWRadioButton;
import com.handinfo.android.uicontrols.controls.DWTextbox;
import com.handinfo.android.uicontrols.controls.DWTitle;
import com.handinfo.android.utils.Tools;

public class UINPCtongji implements IUIWindows{
	private Bitmap m_cp_bm = null;
	private Bitmap m_bm_anxia = null;
	private Bitmap m_cr_tit = null;//标题
	private Bitmap m_bm_close = null;//关闭图片
	private Bitmap m_bm_bj = null;//背景图片
	
	private Bitmap m_limage = null;//关闭图片
	private Bitmap m_rimage = null;//背景图片
	private Bitmap m_tongjiimg = null;//通缉图片
	
	private Bitmap img_yuanbao;
	private Bitmap img_qian;
	
	Bitmap m_cr_choose_ture = null; ///下面的单选被选中时
	Bitmap m_cr_choose_false = null;///下面的单选没被选中时
	
	public final byte liebiao = 0;
	public final byte chakan = 1;
	public final byte mychakan = 2;

	
	public static DWFrame m_Frame = null;
	private DWBackground m_tj_xbj_left_bg;//左侧小背景
	private DWBackground m_tj_xbj_leftup_bg;//左侧小背景
	private DWBackground m_tj_xbj_right_bg;//左侧小背景
	
	private DWCheckbox m_cb[] = new DWCheckbox[3];
	private DWRadioButton m_rb; 
	private String str[]={"时间","元宝","金钱"};
	
	private String strname[][] = {
			{"玩家角色名称","99","99999999","99:99","发起人名称成"},
			{"玩家角色名称","99","99999999","99:99","发起人名称成"},
			{"玩家角色名称","99","99999999","99:99","发起人名称成"},
			{"玩家角色名称","99","99999999","99:99","发起人名称成"},
			{"玩家角色名称","99","99999999","99:99","发起人名称成"},
			{"玩家角色名称","99","99999999","99:99","发起人名称成"},
			{"玩家角色名称","99","99999999","99:99","发起人名称成"},
			{"玩家角色名称","99","99999999","99:99","发起人名称成"},
			{"玩家角色名称","99","99999999","99:99","发起人名称成"},
			{"玩家角色名称","99","99999999","99:99","发起人名称成"},
	};
	
	
	private DWTextbox m_tbs[][]; 
	private DWListSubItem m_lsi[];
	
	private int zym=20;
	private int ym=0;
	private int yms=1;
	private byte type = 0;//0为元宝1为金钱
	private DWListbox m_lb;
	private String m_name = "名字名字名字";
	private long m_money=10000000;
	public byte typey=0;
	
	/**
	 * 绘制NPC弹出列表
	 */
	public void drawliebiao(){
		m_Frame = new DWFrame(DWFrame.FRAME_TYPE_FULL, true);
		m_Frame.setClickClose(false);
		
		
		//背景
		DWBackground m_win_xbj_up_bg = new DWBackground(m_Frame.getShowWidth() - 20,
				m_Frame.getShowHeight() - 20);
		m_win_xbj_up_bg.setNearAnchor(m_Frame, Tools.LEFT_TOP,
				Tools.LEFT_TOP, 10, 10);
		m_Frame.addControl(m_win_xbj_up_bg);
		
		
		//标题
		DWTitle m_tongji_tit = new DWTitle("通缉榜", m_Frame);
		m_Frame.addControl(m_tongji_tit);
		

		
		//叉子
		DWImageBox m_ib_close = new DWImageBox(m_bm_close);
		m_ib_close.setTouchZoomIn(20, 20);
		m_ib_close.setNearAnchor(m_tongji_tit, Tools.RIGHT_TOP, Tools.RIGHT_TOP, 0, 0);
		// 关闭按钮的监听
		m_ib_close.addListener(new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				UIWindows.getInstance().m_npctongji.close((byte)0);
			}
		});
		m_Frame.addControl(m_ib_close);
		
		int y=0;
		if(DWGameManager.AdpaterType == DWGameManager.AD_HIGH){
			y=50;
		}else{
			y=20;
		}
		
		//左侧上小背景
		m_tj_xbj_leftup_bg = new DWBackground(m_bm_bj,200 ,160);
		m_tj_xbj_leftup_bg.setNearAnchor(m_Frame, Tools.LEFT_TOP, Tools.LEFT_TOP,
						20, y);
		m_tj_xbj_leftup_bg.setFill(true);
		m_Frame.addControl(m_tj_xbj_leftup_bg);
		



		
		
		String money="";
		if(m_money>10000){
			money = (m_money/10000)+"万";
		}else{
			money = ""+m_money;
		}
		//通缉最高的玩家名字
		DWTextbox m_feeTexboxn=new DWTextbox(
				m_name+  DWControlTools.CHANGE_ROW +
				""+  DWControlTools.CHANGE_ROW +
				money
				,130);	
		m_feeTexboxn.setNearAnchor(m_tj_xbj_leftup_bg, Tools.LEFT_TOP, Tools.LEFT_TOP
				,65,
				m_tj_xbj_leftup_bg.getShowHeight()-m_feeTexboxn.getShowHeight()>>1);
		
		m_feeTexboxn.addListener(new DWListener() {
			
			public void OnDoubleClick() {
				// TODO Auto-generated method stub
				
			}
			
			public void OnClick() {
				// TODO Auto-generated method stub
				drawmenu2();
			}
		});
		
		m_Frame.addControl(m_feeTexboxn);	
		
		//通缉字样
		DWImageBox tongji = new DWImageBox(m_tongjiimg);
		tongji.setNearAnchor(m_tj_xbj_leftup_bg, Tools.RIGHT_TOP, Tools.RIGHT_TOP, 0, -20);
		m_Frame.addControl(tongji);	
		
		
		
		DWImageBox qians;
		
		if(typey == 0){
			qians = new DWImageBox(img_qian);
		}else{
			qians = new DWImageBox(img_yuanbao);
		}

		qians.setNearAnchor(m_feeTexboxn, Tools.LEFT_TOP, Tools.LEFT_TOP,(int)DWFont.getDefaultFont().stringWidth(money)+2,(int)DWFont.getDefaultFont().getFontHeight()* 2 + 13);
		
		m_Frame.addControl(qians);	
		
		
		//人物图像
		if(m_firstRole!=null){
			DWAnimationBox m_role_animation = new DWAnimationBox(m_firstRole);
			m_role_animation.setNearAnchor(m_tj_xbj_leftup_bg,  Tools.LEFT_TOP, Tools.LEFT_TOP,5,m_tj_xbj_leftup_bg.getShowHeight()-m_role_animation.getShowHeight()>>1);
			m_Frame.addControl(m_role_animation);
		}
		
		
		//左侧小背景
		int y1 = 0;
		int h = 0;
		if(DWGameManager.AdpaterType == DWGameManager.AD_HIGH){
			y1=230;
			h = 360;
		}else{
			y1=190;
			h = 160;
		}
		
		m_tj_xbj_left_bg = new DWBackground(m_bm_bj,200 ,h);
		m_tj_xbj_left_bg.setNearAnchor(m_Frame, Tools.LEFT_TOP, Tools.LEFT_TOP,
						20, y1);
		m_tj_xbj_left_bg.setFill(true);

		m_Frame.addControl(m_tj_xbj_left_bg);
		
		

		
		
		
		//通缉令规则
		
		DWTextbox m_feeTexbox=new DWTextbox("通缉令规则："+  DWControlTools.CHANGE_ROW +
				"玩家可在聊天、仇敌等界面，通缉敌对阵营玩家。通过通缉榜查看目标位置，击杀后目标将损失金钱和属性。"
				,180);	

		if(DWGameManager.AdpaterType == DWGameManager.AD_HIGH){
		}else{
			m_feeTexbox.setFont(DWFont.getFont(18));
		}

		m_feeTexbox.setNearAnchor(m_tj_xbj_left_bg, Tools.LEFT_TOP, Tools.LEFT_TOP,10,2);
		m_Frame.addControl(m_feeTexbox);	
		
		//时间元宝金钱选择框		
		int y2 = 0;
		if(DWGameManager.AdpaterType == DWGameManager.AD_HIGH){
			y2= m_Frame.getShowHeight() - 60;
		}else{
			y2=360;
		}
		m_rb = new DWRadioButton(str, 3,
				m_cr_choose_ture.getWidth()+ (int)DWFont.getDefaultFont().stringWidth(str[0]) + 5, 
				(int)m_cr_choose_ture.getHeight(), m_cr_choose_false, m_cr_choose_ture);
		
		m_rb.setNearAnchor(m_Frame, Tools.LEFT_TOP, Tools.LEFT_TOP,10,y2);
		

		
		m_rb.addListener(ontouch1);
		
		Tools.debugPrintln("init indexrb : " + indexrb);
		m_rb.setSelectIndex(indexrb);//选择下标
		
		m_Frame.addControl(m_rb);
		
		
		
		
		
		//查询列表

		
		DWTextbox tbs1 = new DWTextbox("<mark c=FFC004>"+"通缉目标"+"</mark>");
		DWTextbox tbs2 = new DWTextbox("<mark c=FFC004>"+"等级"+"</mark>");
		DWTextbox tbs3 = new DWTextbox("<mark c=FFC004>"+"酬金"+"</mark>");
		DWTextbox tbs4 = new DWTextbox("<mark c=FFC004>"+"时间"+"</mark>");
		DWTextbox tbs5 = new DWTextbox("<mark c=FFC004>"+"发布人"+"</mark>");
		int x3[] = new int[5];
		int x4[] = new int[5];
		int y3 = 0;
		if(DWGameManager.AdpaterType == DWGameManager.AD_HIGH){
			x3[0] = 250;
			x3[1] = 460;
			x3[2] = 650;
			x3[3] = 850;
			x3[4] = 1040;
			y3 = 25;
			
			x4[0] = 20;
			x4[1] = 230;
			x4[2] = 420;
			x4[3] = 620;
			x4[4] = 810;
		}else{
			y3 = 15;
			x3[0] = 250;
			x3[1] = 360;
			x3[2] = 450;
			x3[3] = 550;
			x3[4] = 640;
			
			x4[0] = 20;
			x4[1] = 130;
			x4[2] = 220;
			x4[3] = 320;
			x4[4] = 410;
		}
		
		
		tbs1.setNearAnchor(m_Frame,  Tools.LEFT_TOP,  Tools.LEFT_TOP,x3[0],y3);
		tbs2.setNearAnchor(m_Frame,  Tools.LEFT_TOP,  Tools.LEFT_TOP,x3[1],y3);
		tbs3.setNearAnchor(m_Frame,  Tools.LEFT_TOP,  Tools.LEFT_TOP,x3[2],y3);
		tbs4.setNearAnchor(m_Frame,  Tools.LEFT_TOP,  Tools.LEFT_TOP,x3[3],y3);
		tbs5.setNearAnchor(m_Frame,  Tools.LEFT_TOP,  Tools.LEFT_TOP,x3[4],y3);
		
		m_Frame.addControl(tbs1);
		m_Frame.addControl(tbs2);
		m_Frame.addControl(tbs3);
		m_Frame.addControl(tbs4);
		m_Frame.addControl(tbs5);
		
		int ws=0;
		int hs=0;
		if(DWGameManager.AdpaterType == DWGameManager.AD_HIGH){
			ws = 1200;
			hs =  600;
		}else{
			ws = 520;
			hs = 300;
		}
		m_lb = new DWListbox(ws, hs);
		m_lb.setNearAnchor(m_Frame, Tools.LEFT_TOP,
				Tools.LEFT_TOP, 230,y3+DWFont.getDefaultFont().getHeight());
		
		
		
		m_tbs = new DWTextbox[strname.length][strname[0].length]; 
		m_lsi = new DWListSubItem[strname.length];
		
		DWImageBox[] m_qian = new DWImageBox[strname.length];
		
		for(int i=0;i<m_lsi.length;i++){
			m_lsi[i] = new DWListSubItem();
			
			m_tbs[i][0] = new DWTextbox("");
			if(zytype[i]!=DWGameManager.getInstance().m_role.m_faction){
				m_tbs[i][0].setText("<mark c=FF0000>"+strname[i][0]+"</mark>");
			}else{
				m_tbs[i][0].setText("<mark c=003CFF>"+strname[i][0]+"</mark>");
			}
			m_tbs[i][0].setNearAnchor(m_lsi[i],  Tools.LEFT_TOP,  Tools.LEFT_TOP,
					x4[0]+(tbs1.getShowWidth()-(int)DWFont.getDefaultFont().stringWidth(strname[i][0])>>1),0);
			m_lsi[i].addControls(m_tbs[i][0]);
			
			m_tbs[i][1] = new DWTextbox("");
			m_tbs[i][1].setText(strname[i][1]);
			m_tbs[i][1].setNearAnchor(m_lsi[i],  Tools.LEFT_TOP,  Tools.LEFT_TOP,
					x4[1]+(tbs2.getShowWidth()-(int)DWFont.getDefaultFont().stringWidth(strname[i][1])>>1),0);
			m_lsi[i].addControls(m_tbs[i][1]);
			
			m_tbs[i][2] = new DWTextbox("");
			m_tbs[i][2].setText(strname[i][2]);
			m_tbs[i][2].setNearAnchor(m_lsi[i],  Tools.LEFT_TOP,  Tools.LEFT_TOP,
					x4[2]+(tbs3.getShowWidth()-((int)DWFont.getDefaultFont().stringWidth(strname[i][2])+20)>>1),0);
			if(types[i]==0){
				m_qian[i] = new DWImageBox(img_qian);
			}else{
				m_qian[i] = new DWImageBox(img_yuanbao);
			}
			m_qian[i].setNearAnchor(m_lsi[i], Tools.LEFT_TOP,  Tools.LEFT_TOP,
					x4[2]+(int)DWFont.getDefaultFont().stringWidth(strname[i][2])+(tbs3.getShowWidth()-((int)DWFont.getDefaultFont().stringWidth(strname[i][2])+20)>>1),3);
			m_lsi[i].addControls(m_tbs[i][2]);
			m_lsi[i].addControls(m_qian[i]);
			
			m_tbs[i][3] = new DWTextbox("");
			m_tbs[i][3].setText(strname[i][3]);
			m_tbs[i][3].setNearAnchor(m_lsi[i],  Tools.LEFT_TOP,  Tools.LEFT_TOP,
					x4[3]+(tbs4.getShowWidth()-(int)DWFont.getDefaultFont().stringWidth(strname[i][3])>>1),0);
			m_lsi[i].addControls(m_tbs[i][3]);
			
			m_tbs[i][4] = new DWTextbox("");
			m_tbs[i][4].setText(strname[i][4]);
			m_tbs[i][4].setNearAnchor(m_lsi[i],  Tools.LEFT_TOP,  Tools.LEFT_TOP,
					x4[4]+(tbs5.getShowWidth()-(int)DWFont.getDefaultFont().stringWidth(strname[i][4])>>1),0);
			m_lsi[i].addControls(m_tbs[i][4]);

			
			
			
			m_lb.addSubItem(m_lsi[i]);
		
		}
		
		m_lb.addListener(ontouch2);
		
		
		m_Frame.addControl(m_lb);
		
		
		
		
		
		//中间显示页码
		int x5=0;
		int y5=0;
		DWImageBox m_lift = new DWImageBox(m_limage);
		DWTextbox tbss = new DWTextbox(yms+"/"+zym);
		DWImageBox m_right = new DWImageBox(m_rimage);
		
		
		if(DWGameManager.AdpaterType == DWGameManager.AD_HIGH){
			x5 = 600;
			y5 = m_Frame.getShowHeight() - 20 - m_lift.getShowHeight();
		}else{
			x5 = 380;
			y5 = 360;
		}

		
		//翻页显示左

		m_lift.setNearAnchor(m_Frame, Tools.LEFT_TOP, Tools.LEFT_TOP, x5, y5);
		// 关闭按钮的监听
		m_lift.addListener(new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				if(ym>0){
					ym--;
					yms = ym+1;
					DWControlsManager.getInstance().removeControl(m_Frame);	
//					drawliebiao();
					sendDuelTongjis(paixu, (short)ym, (short)10);
				}
			}
		});
		
		m_Frame.addControl(m_lift);
		

		tbss.setNearAnchor(m_lift, Tools.LEFT_TOP, Tools.LEFT_TOP, m_lift.getShowWidth()+15, 
				(m_lift.getShowHeight()-(int)DWFont.getDefaultFont().getFontHeight()>>1));
		m_Frame.addControl(tbss);
		

		//翻页显示右

		m_right.setNearAnchor(m_lift, Tools.LEFT_TOP, Tools.LEFT_TOP, m_lift.getShowWidth()+tbss.getShowWidth()+30, 0);
		// 关闭按钮的监听
		m_right.addListener(new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				if((ym+1)<zym){
					ym++;
					yms = ym+1;
					DWControlsManager.getInstance().removeControl(m_Frame);	
					//drawliebiao();
					sendDuelTongjis(paixu, (short)ym, (short)10);
				}
			}
		});
		
		m_Frame.addControl(m_right);
		
		
		
		
		
		DWControlsManager.getInstance().addControl(m_Frame);
		
	}
	
	public byte paixu=3;
	
	public int indexrb;
	
	public DWListener ontouch1 = new DWListener(){

		public void OnDoubleClick() {
			// TODO Auto-generated method stub
		}

		public void OnClick() {
			// TODO Auto-generated method stub
			indexrb = m_rb.getSelectIndex();
			Tools.debugPrintln("indexrb:"+indexrb);
			if(m_rb.getSelectIndex()==0){//时间
				paixu=3;
			}else if(m_rb.getSelectIndex()==1){//元宝
				paixu=1;
			}else if(m_rb.getSelectIndex()==2){//金钱
				paixu=2;
			}
			yms=1;
			ym=0;
			Tools.debugPrintln("paixu"+paixu);
			DWControlsManager.getInstance().removeControl(m_Frame);	
			sendDuelTongjis(paixu, (short)0, (short)10);
		}
		
	};
	public DWListener ontouch2 = new DWListener(){

		public void OnDoubleClick() {
			// TODO Auto-generated method stub
		}

		public void OnClick() {
			// TODO Auto-generated method stub
			index = m_lb.getTouchIndex();
			drawmenu();
		}
		
	};
	public int index;
	private String strs[]={"查看","查询位置"};
	private DWPopMenu m_cp_pm;
	public void drawmenu(){
		m_cp_pm = new DWPopMenu(strs,m_cp_bm);
		m_cp_pm.setDownImage(m_bm_anxia);
	
		m_cp_pm.addListener(new DWListener() {
			
			public void OnDoubleClick() {
			}
			
			public void OnClick() {
			
				int m_si_index = m_cp_pm.getIndex();
				
				//GameActor ar = DWGameManager.getInstance().m_role.m_targetActor;
				switch(m_si_index){
				case 0://查看
					DWGameManager.getInstance().getSendMessage().sendSeeOtherRoleInfo(m_id[index]);
					
					break;
				case 1://寻找位置
					DWGameManager.getInstance().getSendMessage().sendEnemyPosition(m_id[index]);

					break;
				}
			}
		});
		DWControlsManager.getInstance().addControl(m_cp_pm);
	}
	
	public void drawmenu2(){
		m_cp_pm = new DWPopMenu(strs,m_cp_bm);
		m_cp_pm.setDownImage(m_bm_anxia);
	
		m_cp_pm.addListener(new DWListener() {
			
			public void OnDoubleClick() {
			}
			
			public void OnClick() {
			
				int m_si_index = m_cp_pm.getIndex();
				
				//GameActor ar = DWGameManager.getInstance().m_role.m_targetActor;
				switch(m_si_index){
				case 0://查看
					DWGameManager.getInstance().getSendMessage().sendSeeOtherRoleInfo(m_roleid);
					
					break;
				case 1://寻找位置
					DWGameManager.getInstance().getSendMessage().sendEnemyPosition(m_roleid);

					break;
				}
			}
		});
		DWControlsManager.getInstance().addControl(m_cp_pm);
	}
	
	public void init() {
		// TODO Auto-generated method stub
		m_cp_bm = UIWindows.createImage("/img/newui/anniu_6.gnp");
		m_bm_anxia = UIWindows.createImage("/img/newui/anniu_6ax.gnp");
		m_cr_tit = UIWindows.createImage("/img/newui/dati_1.gnp");
		m_bm_close = UIWindows.createImage("/img/newui/fanhuianniu_1.gnp");
		m_bm_bj = UIWindows.createImage("/img/newui/beibaobj_1.gnp");
		m_cr_choose_ture = UIWindows.createImage("/img/newui/xuanzhonganniu_1.gnp");////单选被选中的图片
		m_cr_choose_false = UIWindows.createImage("/img/newui/xuanzhonganniu_2.gnp");//单选没被选的图片
		
		m_limage = UIWindows.createImage("/img/newui/haoyoufyan_2.gnp");//单选没被选的图片
		m_rimage = UIWindows.createImage("/img/newui/haoyoufyan_1.gnp");//单选没被选的图片
		
		img_yuanbao=UIWindows.createImage("/img/newui/yuanbao_1.gnp");
		img_qian=UIWindows.createImage("/img/newui/jinbi_1.gnp");
		m_tongjiimg=UIWindows.createImage("/img/newui/tongji_1.gnp");
	}

	public void open(byte index) {
		// TODO Auto-generated method stub

		for(int i=0;i<m_cb.length;i++){
			m_cb[i] = new DWCheckbox();
		}
		m_cb[0].setChecked(true);
		m_cb[1].setChecked(false);
		m_cb[2].setChecked(false);
	
		drawliebiao();


	}

	public void close(byte index) {
		// TODO Auto-generated method stub
		indexrb = 0;
		yms=1;
		ym=0;
		m_tongji = true;
		DWControlsManager.getInstance().removeControl(m_Frame);
	}

	public void dispose() {
		// TODO Auto-generated method stub
		
	}

	public void logic() {
		// TODO Auto-generated method stub
		
	}
	/**
	 * 仇敌的具体位置
	 * 
	 * @param di
	 * @throws IOException
	 */
	public void recvSocialEnemyPosition(DataInputStream dis)
			throws IOException
	{
//		DataInputStream dis=null;
		short state = dis.readShort();// 0失败1成功
		String msg = dis.readUTF(); // 失败有
		if (state == 0) {
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_C, msg);
			return;
		}
		String location = dis.readUTF(); // 仇敌具体位置
		String name = dis.readUTF();
		

		
		final DWMessageBox socialmb = new DWMessageBox("", name + "当前所在的位置： " + location,"传送","取消");
		socialmb.addListener(new DWListener() {
			public void OnDoubleClick()
			{
			}

			public void OnClick()
			{
				if (socialmb.getResult() == DWMessageBox.SOFTKEY_OK) {
					DWControlsManager.getInstance().removeControl(socialmb);
				}
				else if (socialmb.getResult() == DWMessageBox.SOFTKEY_BACK) {
					DWControlsManager.getInstance().removeControl(socialmb);
				}
			}
		});
		DWControlsManager.getInstance().addControl(socialmb);
	}
	public long m_id[];//角色ID
	public byte types[];//赏金类型
	public byte zytype[];//阵营
	public long tjl_id[];//通缉令ID
	private boolean m_tongji = true;
	public Resource m_resource = new Resource();
	public Role m_firstRole;
	public long m_roleid=0;

	/**
	 * 通缉榜
	 */
	public void recvSocialTongji(DataInputStream dis)
			throws IOException
	{		
		Tools.debugPrintln("接收"+GameProtocol.SC_WANTED_LIST);
		
		byte state = dis.readByte();
		Tools.debugPrintln("state:"+state);
		
		if(state == 1){
			return;
		}
		
		zym = dis.readShort();
		byte type = dis.readByte();
		ym = dis.readShort();
		short tjsl = dis.readShort();
		
		
		if(tjsl==0){
			indexrb = 0;
			yms=1;
			ym=1;
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "暂无通缉信息！");
			return;
		}
		switch (type) {
		case 1:
			indexrb = 1;
			break;
		case 2:
			indexrb = 2;
			break;
		case 3:
			indexrb = 0;
			break;

		default:
			break;
		}
		
		strname = new String[tjsl][5];
		m_id = new long[tjsl];
		zytype = new byte[tjsl];
		tjl_id =  new long[tjsl];
		types = new byte[tjsl];
		int[] time = new int[tjsl];
		
		Tools.debugPrintln("tjsl"+tjsl);
		for(int i=0;i<tjsl;i++){
			tjl_id[i] = dis.readLong();//通缉令ID
			m_id[i] = dis.readLong();//角色ID
			strname[i][0]=dis.readUTF();//被通缉角色名字
			types[i] = dis.readByte();//赏金类型
			long money = dis.readLong();//金额
			strname[i][2] =""+money;
			
			
			time[i]=dis.readInt();//剩余时间
			
			strname[i][3]=""+(time[i]/3600)+":"+(time[i]%3600/60);
			
			strname[i][1]=""+dis.readInt();//等级
			zytype[i]=dis.readByte();//阵营
			strname[i][4]=dis.readUTF();//发布人角色名字
			
			
			byte sex = dis.readByte();//性别
			byte vocations = dis.readByte();//职业
			int size = 5;
			String[] urls = new String[size];
			
			
			for (int j = 1; j < size; j++) {
				
				urls[j] = dis.readUTF();
			}
			
			if(m_tongji){
				m_name = strname[i][0];
				m_roleid = m_id[i];
				typey = types[i];
				m_money = money;
				
				try {
						m_firstRole = new Role(m_resource);
						
						m_firstRole.m_vocation = vocations;//职业
						m_firstRole.m_sex = (byte)sex;//性别
						m_firstRole.initRoleAnims(m_resource, urls);
						
					urls = null;
				}
				catch (Exception e) {
					Tools.debug(e);
				}
				
				m_tongji=false;
			}
		}
		
		drawliebiao();
		
	}
	
	//发送通缉榜翻页指令
	/**
	 * @param type排序
	 * @param ye页码
	 * @param tiaoshu显示条数
	 */
	public void sendDuelTongjis(byte type,short ye,short tiaoshu)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type);
			dos.writeShort(ye);
			dos.writeShort(tiaoshu);
			DWGameManager
					.getInstance()
					.getConnection()
					.sendMessage(0, GameProtocol.SC_WANTED_SORT,
							baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.SC_WANTED_SORT + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			Tools.debug(e);
		}
	}
	/**
	 * 通缉令倒计时
	 */
	public void recvSocialTongjibuff(DataInputStream dis){
		Tools.debugPrintln("接收"+GameProtocol.SC_WANTED_DEBUFF);
		if(dis!=null){
			
			try {
				byte state = dis.readByte();
				
				
				if(state==0){
					UIWindows.getInstance().m_main.m_tongji_buff = false;
					if(UIWindows.getInstance().m_main.m_tongjibuff_time!=null){
						UIWindows.getInstance().m_main.m_tongjibuff_time.setShow(false);
						UIWindows.getInstance().m_main.m_tongji.setShow(false);
						UIWindows.getInstance().m_main.m_changjing_start_time = 0;
						UIWindows.getInstance().m_main.m_tongji_time = 0;
					}
					return;
				}else{
					byte type = dis.readByte();
					UIWindows.getInstance().m_main.m_tongji_buff = true;
					UIWindows.getInstance().m_main.m_tongji_time = dis.readLong();
					UIWindows.getInstance().m_main.m_changjing_start_time = System.currentTimeMillis();// 读取时截取系统时间
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
	}
	
}
